package cn.yunhe.service.serviceImpl;

import cn.yunhe.dao.UserDao;
import cn.yunhe.entity.User;
import cn.yunhe.service.UserService;
import cn.yunhe.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    @Qualifier("userDao")
    public UserDao userDao;
    @Override
    public User getUserByName(User user) {
       User user1 =  userDao.selectUserByName(user.getUserName());
        return user1;
    }

    @Override
    public User login(User user) {
        user.setPassword(Md5Util.doMd5(user.getPassword(),user.getUserName()));
        return  userDao.login(user);
    }

    @Override
    public void addUser(User user) {
        user.setPassword(Md5Util.doMd5(user.getPassword(),user.getUserName()));
        userDao.addUser(user);
    }

    @Override
    public int  updateUser(User user) {
        user.setPassword(Md5Util.doMd5(user.getPassword(),user.getUserName()));
        return userDao.updateUser(user);
    }

    @Override
    public int  updatePassword(User user) {
        user.setPassword(Md5Util.doMd5(user.getPassword(),user.getUserName()));
        return userDao.updatePassword(user);
    }
    @Override
    public User getUserById(int id) {
        return userDao.getUserById(id);
    }

    @Override
    public void addUser2Role(Map map) {
        userDao.addUser2Role(map);
    }
}
